﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.Audio;

namespace Nirvana
{
    /// <summary>
    /// audioSource控制参数
    /// </summary>
    [Serializable]
    public struct AudioSubItemData
    {
        [SerializeField]
        [Tooltip("The audio to play.")]
        private AudioClip audioClip;

        [Tooltip("The output audio mixer group, override the parent if valid.")]
        [SerializeField]
        private AudioMixerGroup mixerGroup;

        [SerializeField]
        [Tooltip("The weight of this sub-item to play in a AudioItem.")]
        private float weight;

        [SerializeField]
        [Tooltip("The volume of this audio.")]
        [Range(0f, 1f)]
        private float volume;

        [Range(0f, 1f)]
        [Tooltip("The random volume add or sub on the base volume.")]
        [SerializeField]
        private float randomVolume;

        [SerializeField]
        [Tooltip("The pitch shift for this audio.")]
        private float pitch;

        [SerializeField]
        [Tooltip("The random pitch add or sub on the base pitch.")]
        private float randomPitch;

        [Tooltip("The delay of this audio.")]
        [SerializeField]
        private float delay;

        [Tooltip("The random delay add or sub on the base delay.")]
        [SerializeField]
        private float randomDelay;

        [SerializeField]
        [Tooltip("The start at point of this audio.")]
        private float startAt;

        [SerializeField]
        [Tooltip("The random start at point add or sub on the base delay.")]
        private float randomStartAt;

        /// <summary>
        /// 音量淡入淡出时间
        /// </summary>
        [Tooltip("The fade in time.")]
        [SerializeField]
        private float fadeInTime;

        [Tooltip("The fade out time.")]
        [SerializeField]
        private float fadeOutTime;

        public AudioClip GetAudioClip()
        {
            return this.audioClip;
        }

        public  AudioMixerGroup GetMixerGroup()
        {
            return this.mixerGroup;
        }

        public float GetWeight()
        {
            return this.weight;
        }

        public float GetVolume()
        {
            float num = UnityEngine.Random.Range(-1f, 1f) * this.randomVolume;
            return this.volume + num;
        }

        public float GetPitch()
        {
            float num = UnityEngine.Random.Range(-1f, 1f) * this.randomPitch;
            return this.pitch + num;
        }

        public float GetDelay()
        {
            float num = UnityEngine.Random.Range(-1f, 1f) * this.randomDelay;
            return this.delay + num;
        }

        public float GetStartAt()
        {
            float num = UnityEngine.Random.Range(-1f, 1f) * this.randomStartAt;
            return this.startAt + num;
        }

        public float GetFadeInTime()
        {
            return this.fadeInTime;
        }
        public float GetFadeOutTime()
        {
            return this.fadeOutTime;
        }

        public void Clear()
        {
            this.audioClip = null;
            this.mixerGroup = null;
            this.weight = 0f;
            this.volume = 1f;
            this.randomVolume = 0f;
            this.pitch = 1f;
            this.randomPitch = 0f;
            this.delay = 0f;
            this.randomDelay = 0f;
            this.startAt = 0f;
            this.randomStartAt = 0f;
            this.fadeInTime = 0f;
            this.fadeOutTime = 0f;
        }
    }
}

